import {ElMessage} from "element-plus";

export default {
  install(app: any) {
    app.directive('clipboard', {
      created(el: any, binding: any) {
        el.addEventListener('click', () => {
          const inputElement = document.createElement("textarea")
          inputElement.value = binding.value
          // console.log(inputElement.value)
          document.body.appendChild(inputElement);
          inputElement.select()
          document.execCommand('copy')
          const parentElement = inputElement.parentNode
          parentElement!.removeChild(inputElement)
          ElMessage.success("内容已复制到剪切板！")
        })
      }
    })
  }
}
